function formatTime(format, date = new Date()) {
    const map = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'H+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds(),
        'y+': date.getFullYear()
    }
    for (const k in map) {
        const reg = new RegExp('(' + k + ')')
        if (reg.test(format)) {
            const str = RegExp.$1
            format = format.replace(str, (map[k] + '').length > 1 ? map[k] : '0' + map[k])
        }
    }
    return format
}
// console.log(formatTime('yy-MM-dd HH: mm: ss'));

const compareTime = (startTime, endTime) =>  {
    const interval = [startTime.getTime(), endTime.getTime()]
    const now = new Date().getTime()
    let num = 3
    if (now < interval[0]) {
        num = 1
    } else if (now > interval[1]) {
        num = 2
    }
    return num
}
module.exports = {
    formatTime,
    compareTime
}
